package naruto.dynamicanalysis.tracing;

import gov.nasa.jpf.*;
import gov.nasa.jpf.jvm.*;
import gov.nasa.jpf.jvm.bytecode.*;
import naruto.datastructures.instruction.MethodInstruction;
import naruto.datastructures.trace.*;

/**
 *
 * @author nacuong
 */
public class MethodCallTracer extends ListenerAdapter{
  MethodCallTrace methodCallTrace;

  public MethodCallTracer(){
    methodCallTrace = new MethodCallTrace();
  }

  public MethodCallTrace run(String[] args){
    Config conf = JPF.createConfig(args);
    JPF jpf = new JPF(conf);
    jpf.addListener(this);
    jpf.run();

    return this.methodCallTrace;
  }

  @Override
  public void instructionExecuted(JVM jvm){
    Instruction insn = jvm.getLastInstruction();
    if (insn instanceof InvokeInstruction)
      methodCallTrace.add(new MethodInstruction((InvokeInstruction)insn));     
  }
}
